<template>
  <div class="record-detail">
    <h2 class="title">记录详情</h2>

    <div class="record-header">
      <img :src="recordDetail.thumbnail" alt="缩略图" class="thumbnail" />
      <div class="record-info">
        <p><strong>记录ID:</strong> {{ recordID }}</p>
        <p><strong>上传用户:</strong> {{ recordDetail.uploaderName || '未知用户' }}</p>
        <p><strong>用户等级:</strong> {{ recordDetail.uploaderLevel || '暂无信息' }}</p>
        <p><strong>文件数:</strong> {{ files.length }}</p>
      </div>
    </div>

    <div class="file-list">
      <h3>相关文件</h3>
      <ul v-if="files.length > 0">
        <li v-for="(file, index) in files" :key="index" class="file-item">
          <p><strong>文件路径:</strong> {{ file.filePath }}</p>
          <p><strong>文件简介:</strong> {{ file.fileIntroduction }}</p>
        </li>
      </ul>
      <p v-else>暂无文件信息</p>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { getRecordDetail } from '@/api/record'; // 导入封装的 API 函数

const route = useRoute();
const recordID = route.params.record_id; // 从路由中获取 record_id
console.log('当前记录ID:', recordID);
const files = ref([]);
const recordDetail = ref({
  thumbnail: '',
  uploaderName: '',
  uploaderLevel: '',
});

// 获取记录详情数据
const fetchRecordDetail = async () => {
  try {
    const data = await getRecordDetail(recordID); // 调用封装的 API 函数
    console.log('记录详情数据:', data);

    files.value = data.files || [];
    recordDetail.value = {
      thumbnail: data.thumbnail || '',
      uploaderName: data.uploaderName || '未知用户',
      uploaderLevel: data.uploaderLevel || '暂无信息',
    };
  } catch (error) {
    files.value = [];
    recordDetail.value = {
      thumbnail: '',
      uploaderName: '未知用户',
      uploaderLevel: '暂无信息',
    };
  }
};

onMounted(() => {
  fetchRecordDetail();
});
</script>

<style scoped>
.record-detail {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  background-color: #fff;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  font-family: 'Arial', sans-serif;
}

.title {
  text-align: center;
  font-size: 24px;
  color: #333;
  margin-bottom: 20px;
}

.record-header {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.thumbnail {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.record-info p {
  margin: 5px 0;
  font-size: 16px;
  color: #555;
}

.file-list {
  margin-top: 20px;
}

.file-list h3 {
  font-size: 20px;
  color: #333;
  margin-bottom: 10px;
}

.file-item {
  padding: 10px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  margin-bottom: 10px;
  background-color: #f9f9f9;
}

.file-item p {
  margin: 5px 0;
  font-size: 14px;
}
</style>